﻿using System.Collections.Concurrent;

namespace ConcurrentBagTest
{
    class ExamInfoRedis
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    internal class Program
    {
        static async Task Main(string[] args)
        {
            ConcurrentBag<ExamInfoRedis> bag = new ConcurrentBag<ExamInfoRedis>();

            // 添加一些示例对象到 ConcurrentBag
            bag.Add(new ExamInfoRedis { Id = 1, Name = "Exam 1" });
            bag.Add(new ExamInfoRedis { Id = 2, Name = "Exam 2" });
            bag.Add(new ExamInfoRedis { Id = 3, Name = "Exam 3" });

            // 转换为列表
            List<ExamInfoRedis> list = bag.ToList();

            // 查找并删除指定元素
            ExamInfoRedis elementToRemove = list.FirstOrDefault(obj => obj.Id == 3);
            if (elementToRemove != null)
            {
                list.Remove(elementToRemove);
            }

            // 将列表中的元素重新放回 ConcurrentBag
            bag = new ConcurrentBag<ExamInfoRedis>(list);
            while (true)
            {
                await Console.Out.WriteLineAsync("测试");
                foreach (var obj in bag)
                {
                    Console.WriteLine(obj.Id);
                }
                await Task.Delay(200);
                await Console.Out.WriteLineAsync("结束");
            }
           
        }
    }
}
